package ac.you.api.ask.e;

import java.rmi.activation.UnknownObjectException;
import java.util.HashMap;
import java.util.Map;

public final class Package {
    private Map<String,Object> params;
    public Package(Map<String, Object> params) {
        this.params = params;
    }
    public static Package create(){
        return new Package(new HashMap<>());
    }
    public Package pack(String space,Object value){
        params.putIfAbsent(space,value);
        return this;
    }
    public <T> T get(Class<T> tClass,String space) throws UnknownObjectException {
        Object value = params.get(space);
        if (tClass.isAssignableFrom(value.getClass())){
            return (T) value;
        }
        throw new UnknownObjectException("Unknown the Value !");
    }
    public Object get(String space){
        return params.get(space);
    }
}
